package com.yunsc.admin.controller.media;

import com.yunsc.common.utils.PageResult;
import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.media.dto.QueryFileDTO;
import com.yunsc.media.dto.FileDTO;
import com.yunsc.media.entity.YunscUploadFileEntity;
import com.yunsc.media.service.YunscUploadFileService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-01-26 10:54
 */
@Api(tags = "文件接口", value = "文件信息接口")
@Slf4j
@RestController
@RequestMapping("files")
public class FileController {

    @Resource
    private YunscUploadFileService uploadFileService;

    @GetMapping("/list")
    public Result<?> queryFileList(QueryFileDTO fileDTO) {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        PageResult<YunscUploadFileEntity> list = uploadFileService.queryFileList(fileDTO, currentStoreId);
        return Result.resultPageList(list);
    }

    @PostMapping("/edit")
    public Result<?> editFile(@RequestBody @Validated({ValidationGroups.Update.class}) FileDTO fileDTO) {
        uploadFileService.editFile(fileDTO);
        return Result.ok();
    }

    @PostMapping("/delete")
    public Result<?> deleteFiles(@RequestBody @Validated({ValidationGroups.Delete.class}) FileDTO fileDTO) {
        uploadFileService.deleteFile(fileDTO.getFileIds());
        return Result.ok();
    }


}
